package com.lc.advertising.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.request.RequestOptions;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.advertising.R;
import com.lc.advertising.app.AppActivity;
import com.lc.advertising.http.glide.GlideApp;
import com.lc.advertising.http.request.EWMApi;
import com.lc.advertising.http.response.EwmBean;
import com.lc.advertising.other.IntentKey;
import com.lc.advertising.util.CourseUtils;
import com.lc.advertising.util.SPUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SpreadActivity extends AppActivity {
    @BindView(R.id.titleBar)
    TitleBar titleBar;
    @BindView(R.id.details)
    TextView details;
    @BindView(R.id.img_ewm)
    ImageView imgEwm;
    private String img_url;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_spread;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        ewm();
        titleBar.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(View v) {
                finish();
            }

            @Override
            public void onTitleClick(View v) {

            }

            @Override
            public void onRightClick(View v) {
                startActivity(SpreadDataActivity.class);
            }
        });
    }

    private void ewm() {

        EasyHttp.post(this)
                .api(new EWMApi().setUid(SPUtil.get(this, IntentKey.UID, "")))
                .request(new HttpCallback<EwmBean>(this) {


                    @Override
                    public void onSucceed(EwmBean data) {
//
                        if (data.getCode() == 200) {
                            img_url = data.getEwm1();
                            GlideApp.with(SpreadActivity.this).load(data.getEwm1()).apply(new RequestOptions().placeholder(R.color.black).error(R.color.black)).into(((ImageView)imgEwm));


                        }


                    }

                });

    }

    @OnClick({R.id.btn_login_commit, R.id.details, R.id.clone})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_login_commit:
              new Thread(new Runnable() {
                  @Override
                  public void run() {
                      CourseUtils.url2bitmap(img_url,SpreadActivity.this);
                  }
              }).start();

                break;
            case R.id.details:
                startActivity(new Intent(this,DanyeActivity.class).putExtra("id","34").putExtra("title","明细奖励"));
                break;
            case R.id.clone:

                break;
        }
    }
}
